package com.clay.algorithm;

import java.util.Stack;

/**
 * @Author : clay
 * @Description:
 * @Date: Create in 22:04 2021/3/20
 * @Modified By:
 */
public class test06 {
    public static void main(String[] args) {
        Solution06 solution06 = new Solution06();
        /*
            构建链表
         */
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(3);
        ListNode listNode3 = new ListNode(5);
        listNode1.next=listNode2;
        listNode2.next=listNode3;
        int[] ints = solution06.reversePrint(listNode1);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }
}

class Solution06{
    public int[] reversePrint(ListNode head) {
        Stack<ListNode> stack=new Stack<ListNode>();
        ListNode temp=head;
        while (temp!=null)
        {
            stack.push(temp);//元素入栈
            temp=temp.next;
        }

        int size=stack.size();
        int[] print=new int[size];
        for (int i= 0; i < size; i++) {
            print[i]=stack.pop().val;//元素出栈
        }
        return print;
    }
}

class ListNode//节点类
{
    int val;
    ListNode next;
    ListNode(int x) { val = x; }

}
